﻿using DataLayer.Types;

namespace ViewModel.Finance
{
    public class FrequencyPropertiesViewModel : ItemPropertiesViewModel<FrequencyItem>
    {
        private decimal mValuePerYear;
        private decimal valueInDays;

        public FrequencyPropertiesViewModel(FrequencyItem frequencyItem) : base(frequencyItem)
        {
            LoadData();
        }

        private void LoadData()
        {
            name = Item.Name;
            mValuePerYear = Item.ValuePerYear;
        }

        public decimal ValuePerYear
        {
            get
            {
                return mValuePerYear;
            }
            set
            {
                mValuePerYear = value;
                OnPropertyChanged("ValuePerYear");
            }
        }

        public decimal ValueInDays
        {
            get
            {
                return valueInDays;
            }
            set
            {
                valueInDays = value;
                OnPropertyChanged("ValueInDays");
            }
        }

        private void CollectData()
        {
            Item.Name = name;
            Item.ValuePerYear = mValuePerYear;
            Item.ValueInDays = valueInDays;
        }

        /// <summary>
        /// Collects the form data into the BudgetItem object and then saves it to the database.
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            CollectData();
            Item.Save();
            return true;
        }
    }
}